hysop.tools.misc module¶
Some utilities to deal with workspaces, slices and other python objects
Utils
: some utilities to handle slices in hysop.WorkSpaceTools
to deal with operators’ local work spaces, see work_spaces.
- class hysop.tools.misc.Utils[source]¶
Bases:
object
tools to handle array and slices.
- static array_to_dict(inarray)[source]¶
convert an array into a dictionnary, keys being the column numbers in array and values the content of each corresponding column transformed into a list of slices like this: column = [1, 4, 2, 6, …] —> [slice(1, 4), slice(2, 6), …]
- class hysop.tools.misc.WorkSpaceTools[source]¶
Bases:
object
Tools to deal with internal work arrays for operators
- static allocate_common_workspaces(work_properties)[source]¶
Allocate a list of common workspaces according to some given properties.
- Parameters:
work_properties (list of lists of tuples) – properties of workspaces. Each component of this list must be the return value of a get_work_properties function (for instance from an operator)
- Returns:
work – workspaces fitting with properties requirements.
- Return type:
list of numpy arrays
Example
# op1, op2 some predifined operators op1.discretize() op2.discretize() wk_prop = [] wk_prop.append(op1.get_work_properties()[‘rwork’]) wk_prop.append(op2.get_work_properties()[‘rwork’]) work = Utils.find_common_workspace(wk_prop)
op1.setup(rwork=work) op2.setup(rwork=work) # work is a common internal list of workspaces that can be used by both # operators.
- static check_work_array(lwork, subshape, work=None, data_type=<class 'numpy.float64'>)[source]¶
Check properties of existing working array or allocate some new buffers complient with some properties.
- Parameters:
Notes
work arrays are 1D arrays of size prod(subshape) that are ‘reshaped’ according to the specific needs of each operator. That means that one memory location (the 1D array) may be shared between several operators thanks to the numpy reshape function.